package com.liyuxiang.service.impl;

import com.liyuxiang.domain.LoginUser;
import com.liyuxiang.domain.ResponseResult;
import com.liyuxiang.service.UserService;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
public class UserServiceImpl implements UserService {
    @Override
    public ResponseResult getUserInfo(HttpServletRequest request) {
        UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUserInfo = (LoginUser) authentication.getPrincipal();
        System.out.println(loginUserInfo);
        return new ResponseResult(200, "ok", loginUserInfo);
    }
}
